package com.sunjob.common.util;

import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;
import com.sunjob.common.domain.loginServer.SysUser;

import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-01 9:11
 * mro 工具类
 */
public class MROUtils {
    static {
        IdGeneratorOptions options = new IdGeneratorOptions((short)1);
        YitIdHelper.setIdGenerator(options);
    }

    /**
     * 生成id
     * @return
     */
    public static Long nextId(){
        return YitIdHelper.nextId();
    }

    /**
     * 判断用户格式
     * @param user
     * @return
     */
    public static String verifyUser(SysUser user) {
        String loginName = user.getLoginName();
        // 4-7 个字符 字母开头 只准有字母数字
        if(!Pattern.matches("^[a-zA-Z]{1}[a-zA-Z0-9]{3,6}$",loginName)){
            return "登录名格式错误,只能为3-6位字母开头的数字字母组成";
        }
        String phoneNum = user.getPhonenumber();
        if(!Pattern.matches("^[1]{1}[3457]{1}[0-9]{9}$",phoneNum)){
            return "手机号格式错误";
        }
        if(user.getPassword().length()<6){
            return "密码格式错误,密码长度不能小于6位";
        }
        String email = user.getEmail();
        if(!Pattern.matches("^[0-9a-zA-Z]+@[0-9a-zA-Z]+\\.com",email)){
            return "邮箱格式有误";
        }
        return "success";
    }
}
